package com.qqt.csr.im.controller;

import com.qqt.csr.common.vo.resp.ObjectResponse;
import com.qqt.csr.im.service.AccountService;
import com.qqt.csr.im.service.RoomService;
import com.qqt.csr.im.service.mongo.ConversationService;
import com.qqt.csr.im.service.mongo.MessageService;
import com.qqt.csr.im.vo.req.ConversationReadReqVO;
import com.qqt.csr.im.vo.req.OfflineMessageReqVO;
import com.qqt.csr.im.vo.req.QueryingRoomListReqVO;
import com.qqt.csr.im.vo.resp.MessageRespVO;
import com.qqt.csr.im.vo.resp.RoomRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: yang hao
 * @Date: 2024/10/15 15:52
 * @Description:
 **/
@Slf4j
@Tag(name = "im服务")
@RestController
@RequestMapping("/im")
public class IMController {
    @Autowired
    private ConversationService conversationService;
    @Autowired
    private MessageService messageService;
    @Autowired
    private AccountService accountService;
    @Autowired
    private RoomService roomService;

    @Operation(summary = "离线消息拉取")
    @PostMapping("/offline/pull")
    public ObjectResponse<List<MessageRespVO>> pullOfflineMessage(@RequestBody @Validated OfflineMessageReqVO dto) {
        return ObjectResponse.success(messageService.pullOfflineMessage(dto));
    }

    @Operation(summary = "房间拉取")
    @PostMapping("/room/list")
    public ObjectResponse<List<RoomRespVO>> getRoomList(@RequestBody @Validated QueryingRoomListReqVO req) {
        return ObjectResponse.success(roomService.queryRoomVOList(req));
    }

    @Operation(summary = "会话已读")
    @PostMapping("/read")
    public ObjectResponse<Boolean> readConversation(@RequestBody @Validated ConversationReadReqVO dto) {
        return ObjectResponse.success(messageService.read(dto));
    }
}
